package com.htzos.base.generate.tool;

import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStreamWriter;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;

import com.htzos.base.generate.bean.ColumnTypeEnum;
import com.htzos.base.generate.bean.TableBean;
import com.htzos.common.util.CharacterUtil;
import com.htzos.common.util.PropertiesUtil;


/**
 * 根据单表生成数据库操作代码
 * @author xudezhi
 *
 */
public class GenerateDbCodeBySingleTable {
	
	
	/**
	 * 生成JAVA文件
	 *
	 * @author 徐德志
	 * @time 2016 2016年4月27日 上午11:36:19
	 * @parameter 
	 * @param packageStr
	 * @param tableName
	 * @param columns
	 * @param savePath
	 * @param selectedColumns
	 * @throws Exception
	 */
	public void generateDbJAVAFile(String packageStr, String tableName,String pkName,
			Map<String, TableBean> columns,String savePath, List<String> selectedColumns) throws Exception {
		
		if (null == columns || columns.size() == 0) {
			return;
		}
		
		generateDaoXMLFile(packageStr,tableName,pkName,columns,savePath);
		generateDaoJAVAFile(packageStr,tableName,columns,savePath);
		generateServiceJAVAFile(packageStr,tableName,columns,savePath);
		generateControllerFile(packageStr, tableName, columns, savePath);
		
	}
	
	/**
	 * 生成JSP文件
	 *
	 * @author 徐德志
	 * @time 2016 2016年4月27日 上午11:36:33
	 * @parameter 
	 * @param packageStr
	 * @param tableName
	 * @param columns
	 * @param savePath
	 * @param selectedColumns
	 * @throws Exception
	 */
	public void generateDbJSPFile(String packageStr, String tableName,String titleName,String pkName,
			Map<String, TableBean> columns,String savePath, List<String> selectedColumns) throws Exception {
		
		if (null == columns || columns.size() == 0) {
			return;
		}
		
		generateJSPListFile(packageStr, tableName,titleName, columns, savePath, selectedColumns);
		generateJSPUpdateFile(packageStr, tableName,titleName, columns, savePath);
		generateJSPAddFile(packageStr, tableName,titleName, columns, savePath);
		generateJSPDetailFile(packageStr, tableName,titleName, columns, savePath);
	}
	
	
	
	
	
	/**
	 * 生成数据库操作方法
	 * @param packageStr
	 * @param tableName
	 * @param columns
	 * @param savePath
	 * @return
	 * @throws Exception 
	 */
//	public String generateDbOperatorFile(String packageStr, String tableName,
//			Map<String, TableBean> columns,String savePath, List<String> selectedColumns) throws Exception {
//		
//		if (null == columns || columns.size() == 0) {
//			return "Columns is null!";
//		}
//		
//		generateDaoXMLFile(packageStr,tableName,null,columns,savePath);
//		generateDaoJAVAFile(packageStr,tableName,columns,savePath);
//		generateServiceJAVAFile(packageStr,tableName,columns,savePath);
//		generateControllerFile(packageStr, tableName, columns, savePath);
//		generateJSPListFile(packageStr, tableName, columns, savePath, selectedColumns);
//		generateJSPUpdateFile(packageStr, tableName, columns, savePath);
//		generateJSPAddFile(packageStr, tableName, columns, savePath);
//		
//		File file = new File(savePath);
//		
//		String filePath = file.getParent() + File.separatorChar + CharacterUtil.returnBeanName(tableName) + ".zip";
//		ZipUtils.zip(savePath, filePath);
//		
//		return filePath;
//	}
	
	/**
	 * 生成ServiceJAVA
	 * @param columns
	 * @throws IOException 
	 */
	private void generateServiceJAVAFile(String packageStr, String tableName,
			Map<String, TableBean> columns,String savePath) throws IOException{
		StringBuffer content = new StringBuffer();
		
		String beanName=CharacterUtil.returnBeanName(tableName);
		String mapName=CharacterUtil.firstLowCase(beanName)+"Mapper";
		
		content.append("package " + packageStr + ".service;\r\n");
		content.append("import "+packageStr+".bean."+beanName+";\r\n");
		content.append("import "+packageStr+".dao."+beanName+"Mapper;\r\n");
		content.append("import com.htzos.common.tool.ExtQueryBean;\r\n");
		content.append("import java.util.List;\r\n");
		content.append("import org.springframework.stereotype.Service;\r\n");
		content.append("import org.springframework.transaction.annotation.Propagation;\r\n");
		content.append("import org.springframework.transaction.annotation.Transactional;\r\n");
		content.append("import org.springframework.beans.factory.annotation.Autowired;\r\n");
		
		content.append("@Service\r\n");
		content.append("@Transactional(rollbackFor = Exception.class)\r\n");
		content.append("public class "+beanName+"Service {\r\n");
		content.append("    @Autowired\r\n");
		content.append("    " + beanName+"Mapper "+mapName+";\r\n");
		content.append("    @Transactional(propagation = Propagation.SUPPORTS, readOnly = true)\r\n");
		content.append("    public List<"+beanName+"> "+CharacterUtil.firstLowCase(beanName)+"List("+beanName+" "+CharacterUtil.firstLowCase(beanName)+", ExtQueryBean extQuery){\r\n");
		content.append("       return "+mapName+"."+CharacterUtil.firstLowCase(beanName)+"List("+CharacterUtil.firstLowCase(beanName)+", extQuery);\r\n");
		content.append("    }\r\n");
		content.append("\r\n");	
		content.append("    @Transactional(propagation = Propagation.SUPPORTS, readOnly = true)\r\n");
		content.append("    public Integer "+CharacterUtil.firstLowCase(beanName)+"Total("+beanName+" "+CharacterUtil.firstLowCase(beanName)+", ExtQueryBean extQuery){\r\n");
		content.append("       return "+mapName+"."+CharacterUtil.firstLowCase(beanName)+"Total("+CharacterUtil.firstLowCase(beanName)+", extQuery);\r\n");
		content.append("    }\r\n");
		content.append("\r\n");
		content.append("    @Transactional(propagation = Propagation.SUPPORTS, readOnly = true)\r\n");		
		content.append("    public int "+CharacterUtil.firstLowCase(beanName)+"Update("+beanName+" "+CharacterUtil.firstLowCase(beanName)+"){\r\n");
		content.append("       return "+mapName+"."+CharacterUtil.firstLowCase(beanName)+"Update("+CharacterUtil.firstLowCase(beanName)+");\r\n");
		content.append("    }\r\n");
		content.append("\r\n");
		content.append("    @Transactional(propagation = Propagation.SUPPORTS, readOnly = true)\r\n");				
		content.append("    public int "+CharacterUtil.firstLowCase(beanName)+"Insert("+beanName+" "+CharacterUtil.firstLowCase(beanName)+"){\r\n");
		content.append("       return "+mapName+"."+CharacterUtil.firstLowCase(beanName)+"Insert("+CharacterUtil.firstLowCase(beanName)+");\r\n");
		content.append("    }\r\n");
		content.append("\r\n");	
		content.append("    @Transactional(propagation = Propagation.SUPPORTS, readOnly = true)\r\n");		
		content.append("    public int "+CharacterUtil.firstLowCase(beanName)+"Delete("+beanName+" "+CharacterUtil.firstLowCase(beanName)+"){\r\n");
		content.append("       return "+mapName+"."+CharacterUtil.firstLowCase(beanName)+"Delete("+CharacterUtil.firstLowCase(beanName)+");\r\n");
		content.append("    }\r\n");
		content.append("\r\n");
		content.append("    @Transactional(propagation = Propagation.SUPPORTS, readOnly = true)\r\n");		
		content.append("    public " + beanName + " "+CharacterUtil.firstLowCase(beanName)+"Get(String id){\r\n");
		content.append("       return "+mapName+"."+CharacterUtil.firstLowCase(beanName)+"Get(id);\r\n");
		content.append("    }\r\n");
		content.append("}");
		
		String filePath = savePath+"service/" + CharacterUtil.returnBeanName(tableName) + "Service.java";
		writerFile(filePath, content.toString());
	}
	
	/**
	 * 生成DaoJAVA
	 * @param columns
	 * @throws IOException 
	 */
	private void generateDaoJAVAFile(String packageStr, String tableName,
			Map<String, TableBean> columns,String savePath) throws IOException{

		StringBuffer content = new StringBuffer();
		
		String beanName=CharacterUtil.returnBeanName(tableName);
		
		content.append("package " + packageStr + ".dao;\r\n");
		content.append("import "+packageStr+".bean."+beanName+";\r\n");
		content.append("import com.htzos.common.tool.ExtQueryBean;\r\n");
		content.append("import java.util.List;\r\n");
		content.append("import org.apache.ibatis.annotations.Param;\r\n");
		content.append("import org.springframework.stereotype.Repository;\r\n");
		
		content.append("@Repository\r\n");
		content.append("public interface " + beanName + "Mapper{\r\n");
		
		content.append("    public List<"+beanName+"> "+CharacterUtil.firstLowCase(beanName)+"List(@Param(value=\"" + CharacterUtil.firstLowCase(beanName) + "\")"+beanName+" "+CharacterUtil.firstLowCase(beanName)+ ", @Param(value=\"extQuery\")ExtQueryBean extQuery);\r\n");
		content.append("    public Integer "+CharacterUtil.firstLowCase(beanName)+"Total(@Param(value=\"" + CharacterUtil.firstLowCase(beanName) + "\")"+beanName+" "+CharacterUtil.firstLowCase(beanName)+ ", @Param(value=\"extQuery\")ExtQueryBean extQuery);\r\n");
		content.append("    public int "+CharacterUtil.firstLowCase(beanName)+"Update("+beanName+" "+CharacterUtil.firstLowCase(beanName)+ ");\r\n");
		content.append("    public int "+CharacterUtil.firstLowCase(beanName)+"Insert("+beanName+" "+CharacterUtil.firstLowCase(beanName)+");\r\n");
		content.append("    public int "+CharacterUtil.firstLowCase(beanName)+"Delete("+beanName+" "+CharacterUtil.firstLowCase(beanName)+ ");\r\n");
		content.append("    public " + beanName + " "+CharacterUtil.firstLowCase(beanName)+"Get(String id);\r\n");
		content.append("}");
		
		String filePath = savePath+"dao/" + CharacterUtil.returnBeanName(tableName) + "Mapper.java";
		writerFile(filePath, content.toString());
	}
	
	/**
	 * 生成DaoXml
	 * @param columns
	 * @throws IOException 
	 */
	private void generateDaoXMLFile(String packageStr, String tableName,String pkName,
			Map<String, TableBean> columns,String savePath) throws IOException{

		StringBuffer deftionBuffer = new StringBuffer();
		StringBuffer attrBuffer = new StringBuffer();
		
		String beanName=CharacterUtil.returnBeanName(tableName);
		String attiName=CharacterUtil.firstLowCase(beanName);
		Iterator<String> key = columns.keySet().iterator();
		String columnName;
		
		//生成XML文件头
		deftionBuffer.append("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\r\n");
		deftionBuffer.append("<!DOCTYPE mapper PUBLIC \"-//mybatis.org//DTD Mapper 3.0//EN\" \"http://mybatis.org/dtd/mybatis-3-mapper.dtd\">\r\n");
		deftionBuffer.append("<mapper namespace=\""+packageStr+".dao."+CharacterUtil.returnBeanName(tableName)+"Mapper\">\r\n");
		//生成列表操作
		deftionBuffer.append("<select id=\""+attiName+"List\" resultType=\""+packageStr+".bean."+beanName+"\">\r\n");
		deftionBuffer.append("   select * from `"+tableName+"`\r\n");
		deftionBuffer.append("   where 1=1 \r\n");
		attrBuffer.append("   <if test=\"" + attiName + "!= null\"> \r\n");
		while (key.hasNext()) {
			columnName = key.next();
			TableBean tableBean = columns.get(columnName);
			ColumnTypeEnum columnType = ColumnTypeEnum.instanceOf(tableBean.getColumnType());
			if(String.class.equals(columnType.getObjClass())) {
				attrBuffer.append("       <if test=\"" + attiName + "." + CharacterUtil.firstLowCase(columnName)+" != null and " + attiName + "." + CharacterUtil.firstLowCase(columnName)+" != ''\"> \r\n");
				attrBuffer.append("           AND `"+columnName+"` = #{" + attiName + "." + CharacterUtil.firstLowCase(columnName)+"}  \r\n"); 
				attrBuffer.append("       </if> \r\n");
			} else {
				attrBuffer.append("       <if test=\"" + attiName + "." + CharacterUtil.firstLowCase(columnName)+" != null\"> \r\n");
				attrBuffer.append("           AND `"+columnName+"` = #{" + attiName + "." + CharacterUtil.firstLowCase(columnName)+"}  \r\n"); 
				attrBuffer.append("       </if> \r\n");
			}
		}
		
		attrBuffer.append("   </if> \r\n");
		
		deftionBuffer.append(attrBuffer);
		
		deftionBuffer.append("   <if test=\"extQuery != null\"> \r\n");
		deftionBuffer.append("       <if test=\"extQuery.appendSql != null\"> \r\n");
		deftionBuffer.append("           ${extQuery.appendSql}  \r\n"); 
		deftionBuffer.append("       </if> \r\n");
		deftionBuffer.append("       <if test=\"extQuery.orderBy != null\"> \r\n");
		deftionBuffer.append("           ORDER BY ${extQuery.orderBy} ${extQuery.orderType} \r\n"); 
		deftionBuffer.append("       </if> \r\n");
		if(pkName!=null){
			deftionBuffer.append("       <if test=\"extQuery.orderBy == null\"> \r\n");
			deftionBuffer.append("           ORDER BY "+pkName+" DESC \r\n"); 
			deftionBuffer.append("       </if> \r\n");
		}
		deftionBuffer.append("       <if test=\"extQuery.start != null and extQuery.size != null\"> \r\n");
		deftionBuffer.append("           limit #{extQuery.start}, #{extQuery.size}  \r\n"); 
		deftionBuffer.append("       </if> \r\n");
		deftionBuffer.append("   </if> \r\n");
		deftionBuffer.append("</select>\r\n");
		deftionBuffer.append("\r\n");
		
		//生成total
		deftionBuffer.append("<select id=\""+attiName+"Total\" resultType=\"java.lang.Integer\">\r\n");
		deftionBuffer.append("   select count(1) from `"+tableName+"`\r\n");
		deftionBuffer.append("   where 1=1 \r\n");
		deftionBuffer.append(attrBuffer);
		deftionBuffer.append("   <if test=\"extQuery != null\"> \r\n");
		deftionBuffer.append("       <if test=\"extQuery.appendSql != null\"> \r\n");
		deftionBuffer.append("           ${extQuery.appendSql}  \r\n"); 
		deftionBuffer.append("       </if> \r\n");
		deftionBuffer.append("   </if> \r\n");
		
		deftionBuffer.append("</select>\r\n");
		deftionBuffer.append("\r\n");
		
		//生成更新操作
		deftionBuffer.append("<update id=\""+attiName+"Update\" parameterType=\""+packageStr+".bean."+beanName+"\">\r\n");
		deftionBuffer.append("   update `"+tableName+"`\r\n");
		deftionBuffer.append("   <trim prefix=\"set\" suffixOverrides=\",\">\r\n");
		
		key = columns.keySet().iterator();
		while (key.hasNext()) {
			columnName = key.next();
			deftionBuffer.append("   <if test=\""+CharacterUtil.firstLowCase(columnName)+" != null \">\r\n");
			deftionBuffer.append("       `"+columnName+"` = #{"+CharacterUtil.firstLowCase(columnName)+"},\r\n"); 
			deftionBuffer.append("   </if>\r\n");
		}
		
		//添加更新操作的附加查询条件
		deftionBuffer.append("   </trim>\r\n");
		deftionBuffer.append("   where `id`=#{id}\r\n");
		deftionBuffer.append("</update>\r\n");
		deftionBuffer.append("\r\n");
		
		//生成Get
		deftionBuffer.append("<select id=\""+attiName+"Get\" resultType=\""+packageStr+".bean."+beanName+"\">\r\n");
		deftionBuffer.append("   select * from "+tableName+"\r\n");
		deftionBuffer.append("   where `id`=#{id} \r\n");
		deftionBuffer.append("</select>\r\n");
		deftionBuffer.append("\r\n");
		
		//生成插入操作
		deftionBuffer.append("<insert id=\""+attiName+"Insert\" parameterType=\""+packageStr+".bean."+beanName+"\">\r\n");
		deftionBuffer.append("   insert into `"+tableName+"` \r\n");
		deftionBuffer.append("   <trim prefix=\"set\" suffixOverrides=\",\">\r\n");
		
		key = columns.keySet().iterator();
		while (key.hasNext()) {
			columnName = key.next();
			
			TableBean tableBean = columns.get(columnName);
			ColumnTypeEnum columnType = ColumnTypeEnum.instanceOf(tableBean.getColumnType());
			
			if(String.class.equals(columnType.getObjClass())) {
				deftionBuffer.append("   <if test=\""+CharacterUtil.firstLowCase(columnName)+" != null and "+CharacterUtil.firstLowCase(columnName)+" != ''\">\r\n");
				deftionBuffer.append("       `"+columnName+"` = #{"+CharacterUtil.firstLowCase(columnName)+"},\r\n"); 
				deftionBuffer.append("   </if>\r\n");
			} else {
				deftionBuffer.append("   <if test=\""+CharacterUtil.firstLowCase(columnName)+" != null \">\r\n");
				deftionBuffer.append("       `"+columnName+"` = #{"+CharacterUtil.firstLowCase(columnName)+"},\r\n"); 
				deftionBuffer.append("   </if>\r\n");
			}
		}
		
		deftionBuffer.append("   </trim>\r\n");
		deftionBuffer.append("</insert>\r\n");
		deftionBuffer.append("\r\n");
		//生成删除操作
		deftionBuffer.append("<delete id=\""+attiName+"Delete\" parameterType=\""+packageStr+".bean."+beanName+"\">\r\n");
		deftionBuffer.append("    delete from `"+tableName+"` \r\n");
		deftionBuffer.append("    where `id`=#{id}\r\n");
		deftionBuffer.append("</delete>\r\n");
		deftionBuffer.append("</mapper>");
		
		String filePath = savePath+"dao/" + CharacterUtil.returnBeanName(tableName) + "Mapper.xml";
		writerFile(filePath, deftionBuffer.toString());
	}
	
	private void writerFile(String filePath, String content) {
		
		File file=new File(filePath);
		//如果文件存在配置的不替换就返回
		if (file.exists()) {
			if(PropertiesUtil.FILEREPLACE==false){
				return;
			}else{
				file.delete();
			}
		}
		OutputStreamWriter out = null;
		try {
			out = new OutputStreamWriter(new FileOutputStream(filePath), "UTF-8");
			out.write(content);
			out.close();
		} catch (Exception e) {
			// TODO: handle exception
		} finally {
			if(out != null) {
				try {
					out.close();
				} catch (IOException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}
			}
		}
	}
	
	/**
	 * 生成DaoJAVA
	 * @param columns
	 * @throws IOException 
	 */
	private void generateControllerFile(String packageStr, String tableName,
			Map<String, TableBean> columns,String savePath) throws IOException{

		StringBuffer content = new StringBuffer();
		
		String beanName=CharacterUtil.returnBeanName(tableName);
		String attiName=CharacterUtil.firstLowCase(beanName);
		String serviceName = beanName + "Service";
		String serviceAttiName = CharacterUtil.firstLowCase(serviceName);
		String modelName = packageStr.substring(packageStr.lastIndexOf(".") + 1);
		//拼接上admin、放到admin文件夹下
		modelName="admin/"+modelName;
		
		content.append("package " + packageStr + ".controller;\r\n");
		content.append("import " + packageStr + ".bean." + beanName+";\r\n");
		content.append("import com.htzos.common.tool.ExtQueryBean;\r\n");
		content.append("import com.htzos.base.parent.ctrl.BaseController;\r\n");
		content.append("import java.util.List;\r\n");
		content.append("import javax.annotation.Resource;\r\n");
		content.append("import javax.servlet.http.HttpServletRequest;\r\n");
		content.append("import org.springframework.stereotype.Controller;\r\n");
		content.append("import org.springframework.web.bind.annotation.RequestMapping;\r\n");
		content.append("import org.springframework.web.servlet.ModelAndView;\r\n");
		content.append("import org.springframework.web.servlet.view.RedirectView;\r\n");
		content.append("import " + packageStr + ".service." + beanName + "Service;\r\n");
		content.append("\r\n");
		content.append("@Controller\r\n");
		content.append("@RequestMapping(\"/"+ attiName + "\")\r\n");
		//添加extends BaseController
		content.append("public class " + beanName + "Controller extends BaseController{\r\n");
		content.append("\r\n");
		content.append("    @Resource\r\n");
		content.append("    " + serviceName + " " + serviceAttiName + ";\r\n");
		content.append("\r\n");
		content.append("    @RequestMapping(\"/list\")\r\n");
		//String 改为 ModelAndView
		content.append("    public ModelAndView list(HttpServletRequest request," + beanName + " condition, ExtQueryBean extQuery) {\r\n");
		content.append("        if(extQuery.getPageNum() == null) {\r\n");
		content.append("            extQuery.setSize(10);\r\n");
		content.append("            extQuery.setPageNum(1);\r\n");
		content.append("        }\r\n");
		content.append("\r\n");
		content.append("        extQuery.setTotal(" + serviceAttiName + "." + attiName + "Total(condition, extQuery));\r\n");
		content.append("        List<"+beanName+"> list= " + serviceAttiName + "." + attiName +"List(condition, extQuery);\r\n");
		content.append("        request.setAttribute(\"list\", list);\r\n");
		content.append("        request.setAttribute(\"condition\", condition);\r\n");
		content.append("        request.setAttribute(\"extQuery\", extQuery);\r\n");
		content.append("        request.getSession(true).setAttribute(\"conditionStr\", condition);\r\n");
		content.append("        request.getSession(true).setAttribute(\"extQueryStr\", extQuery);\r\n");
		content.append("        return new ModelAndView(\"" + modelName + "/" + attiName + "List\");\r\n");
		content.append("    }\r\n");
		content.append("\r\n");
		
		content.append("    @RequestMapping(\"/update\")\r\n");
		//String 改为 ModelAndView
		content.append("    public ModelAndView update(HttpServletRequest request, " + beanName + " " + attiName + ") {\r\n");
		content.append("        " + serviceAttiName + "." + attiName + "Update(" + attiName + ");\r\n");
		content.append("        return new ModelAndView(new RedirectView(\"list\"), getSessionQueryString(request));\r\n");
		content.append("    }\r\n");
		content.append("\r\n");
		content.append("    @RequestMapping(\"/updatePage\")\r\n");
		content.append("    public String updatePage(HttpServletRequest request, String id) {\r\n");
		content.append("        " + beanName + " " + attiName + " = " + serviceAttiName + "." + attiName + "Get(id);\r\n");
		content.append("        request.setAttribute(\"" + attiName + "\", " + attiName + ");\r\n");
		content.append("        return \"" + modelName + "/" + attiName + "Update\";\r\n");
		content.append("    }\r\n");
		content.append("\r\n");
		content.append("    @RequestMapping(\"/detail\")\r\n");
		content.append("    public String detail(HttpServletRequest request, String id) {\r\n");
		content.append("        " + beanName + " " + attiName + " = " + serviceAttiName + "." + attiName + "Get(id);\r\n");
		content.append("        request.setAttribute(\"" + attiName + "\", " + attiName + ");\r\n");
		content.append("        return \"" + modelName + "/" + attiName + "Detail\";\r\n");
		content.append("    }\r\n");
		content.append("\r\n");
		content.append("    @RequestMapping(\"/insert\")\r\n");
		//String 改为 ModelAndView
		content.append("    public ModelAndView insert(HttpServletRequest request, " + beanName + " " + attiName + ") {\r\n");
		content.append("        " + serviceAttiName + "." + attiName + "Insert(" + attiName + ");\r\n");
		content.append("        return new ModelAndView(new RedirectView(\"list\"), getSessionQueryString(request));\r\n");
		content.append("    }");
		content.append("\r\n");
		content.append("    @RequestMapping(\"/addPage\")\r\n");
		content.append("    public String addPage() {\r\n");
		content.append("        return \"" + modelName + "/" + attiName + "Add\";\r\n");
		content.append("    }\r\n");
		content.append("\r\n");
		content.append("    @RequestMapping(\"/delete\")\r\n");
		content.append("    public ModelAndView delete(HttpServletRequest request, " + beanName + " " + attiName + ") {\r\n");
		content.append("        " + serviceAttiName + "." + attiName + "Delete(" + attiName + ");\r\n");
		content.append("         return new ModelAndView(new RedirectView(\"list\"), getSessionQueryString(request));\r\n");
		content.append("    }");
		content.append("\r\n");
		content.append("}");
		
		String filePath =savePath+"controller/" + CharacterUtil.returnBeanName(tableName) + "Controller.java";
		writerFile(filePath, content.toString());
	}
	
	/**
	 * 生成JSPListFile
	 * 
	 * @param columns
	 * @throws IOException
	 */
	private void generateJSPListFile(String packageStr, String tableName,String titleName, Map<String, TableBean> columns,
			String savePath, List<String> selectedColumns) throws IOException {

		StringBuffer content = new StringBuffer();
		StringBuffer tdContent = new StringBuffer();
		StringBuffer titleContent = new StringBuffer();
		
		String beanName=CharacterUtil.returnBeanName(tableName);
		String attiName=CharacterUtil.firstLowCase(beanName);
		
		content.append("<%@ page language=\"java\" contentType=\"text/html; charset=UTF-8\" pageEncoding=\"UTF-8\"%>\r\n");
		content.append("<%@ taglib prefix=\"c\" uri=\"http://java.sun.com/jsp/jstl/core\"%>\r\n");
		content.append("<%@ taglib uri=\"http://java.sun.com/jsp/jstl/fmt\" prefix=\"fmt\" %>\r\n");
		content.append("<%@ taglib prefix=\"xdz\" uri=\"/xdztools\" %>\r\n");
		content.append("<!DOCTYPE html>\r\n");
		content.append("<html lang=\"zh-CN\">\r\n");
		content.append("<head>\r\n");
		content.append("<meta charset=\"utf-8\">\r\n");
		content.append("<link rel=\"stylesheet\" href=\"${xdz:domain() }/css/bootstrap.min.css\">\r\n");
		content.append("<link rel=\"stylesheet\" href=\"${xdz:domain() }/css/plugins/morris/morris-0.4.3.min.css\">\r\n");
		content.append("<link rel=\"stylesheet\" href=\"${xdz:domain() }/css/font-awesome.min.css\">\r\n");
		content.append("<link rel=\"stylesheet\" href=\"${xdz:domain() }/css/kkpager_blue.css\">\r\n");
//		content.append("<link rel=\"stylesheet\" href=\"${xdz:domain() }/css/style.min.css\">\r\n");
		content.append("<link rel=\"stylesheet\" href=\"${xdz:domain() }/css/parsley.css\" >\r\n");
		content.append("<title>" +titleName+"列表</title>\r\n");
		content.append("</head>\r\n");
		content.append("<body>\r\n");
		content.append("    <form action=\"../" + attiName + "/list\" id=\"" + attiName + "Form\" method=\"post\">\r\n");
		content.append("        <div class=\"panel panel-default\">\r\n");
		content.append("        	<header class=\"panel-heading\"><h3 class=\"panel-title\">"+titleName+"列表</h3></header>\r\n");
		content.append("        	<div class=\"panel-body\">\r\n");
		content.append("        		<div class=\"row\">\r\n");
		for (Entry<String, TableBean> entry : columns.entrySet()) {
			//获取类型判断是不是时间类型
			String type = columns.get(entry.getKey()).getColumnType();
			ColumnTypeEnum columnType = ColumnTypeEnum.instanceOf(type);
			String objType = columnType.getObjType();
			
			String columnName = CharacterUtil.firstLowCase(entry.getKey());
			if("Date".equals(objType)){
				//时间的处理
				 tdContent.append("                                        <td>${list.str" + CharacterUtil.firstUpperCase(columnName) + " }</td>\r\n");
			}else if("Integer".equals(objType)&&"status".equals(columnName)){
				//状态的处理
	   			 tdContent.append("                                        <td>\r\n");
	   			 tdContent.append("                                             ${xdz:statusVal(list.status) }\r\n");
	   			 tdContent.append("                                        </td>\r\n");
			}else{
				 tdContent.append("                                        <td>${list." + columnName + " }</td>\r\n");
			}
			
			titleContent.append("                                    <th>" + entry.getValue().getRemarks() + "</th>\r\n");
			for (String selectedColumn : selectedColumns) {
				if(selectedColumn.equalsIgnoreCase(columnName)) {
					content.append("           			<div class=\"col-md-2\">\r\n");
					if("Date".equals(objType)){
						content.append("    				<input type=\"text\" name=\"str" + CharacterUtil.firstUpperCase(columnName) + "\" value=\"${condition.str" + CharacterUtil.firstUpperCase(columnName) + "}\" class=\"form-control input-sm\" placeholder=\"" + entry.getValue().getRemarks() + "\" />\r\n");
					}else if("Integer".equals(objType)&&"status".equals(columnName)){
						//状态的处理
						content.append("    				<select name=\"status\" id=\"status\" class=\"form-control input-sm\">\r\n");
						content.append("    				 	<option value=\"\">状态</option>\r\n");
						content.append("    					<option value=\"1\" <c:if test=\"${condition.status == 1}\">selected</c:if>>启用</option>\r\n");
						content.append("    					<option value=\"0\" <c:if test=\"${condition.status == 0}\">selected</c:if>>禁用</option>\r\n");
						content.append("    				</select>\r\n");
					}else{
						content.append("    				<input type=\"text\" name=\"" + columnName + "\" value=\"${condition." + columnName + "}\" class=\"form-control input-sm\" placeholder=\"" + entry.getValue().getRemarks() + "\" />\r\n");
					}
					content.append("           			</div>\r\n");
					break;
				}
			}
		}
		content.append("           			<div class=\"col-md-2\">\r\n");
		content.append("                  		<button class=\"btn btn-primary btn-sm\" type=\"submit\">查询</button>\r\n");
		content.append("           			</div>\r\n");
		content.append("           			<div class=\"col-md-2 pull-right\">\r\n");
		content.append("                  		<button type=\"button\" class=\"btn btn-primary btn-sm pull-right\" onclick=\"openAdd()\">新增</button>\r\n");
		content.append("           			</div>\r\n");
		content.append("        		</div>\r\n");
		content.append("            </div>\r\n");
		content.append("            <div class=\"table-responsive scroll-wrapper\">\r\n");
		content.append("                        <table class=\"table table-striped table-hover table-condensed\">\r\n");
		content.append("                            <thead>\r\n");
		content.append("                                <tr>\r\n");
		content.append(titleContent);
		content.append("                                    <th>操作</th>\r\n");
		content.append("                                </tr>\r\n");
		content.append("                            </thead>\r\n");
		content.append("                            <tbody>\r\n");
		content.append("                                <c:forEach var=\"list\" items=\"${list }\">\r\n");
		content.append("                                    <tr>\r\n");
		content.append(tdContent);
		content.append("                                        <td><a href=\"../" + attiName + "/updatePage?id=${list.id }\">修改</a>");
		content.append(" 											| <a href=\"javascript:void(0)\" onclick=\"detail(${list.id})\">详情</a>");
		content.append(" 											| <a href=\"javascript:void(0)\" onclick=\"del(${list.id})\">删除</a>");
		content.append("                                        </td>");
		content.append("                                    </tr>\r\n");
		content.append("                                </c:forEach>\r\n");
		content.append("                            </tbody>\r\n");
		content.append("                        </table>\r\n");
		content.append("            </div>\r\n");
		content.append("            <div class=\"panel-footer\">\r\n");
		content.append("                  <div id=\"kkpager\"></div>\r\n");
		content.append("            </div>\r\n");
		content.append("    	</div>\r\n");
		content.append("    </form>\r\n");
		content.append("    <script src=\"${xdz:domain() }/js/jquery.min.js\"></script>\r\n");
		content.append("    <script src=\"${xdz:domain() }/js/bootstrap.min.js\"></script>\r\n");
		content.append("    <script src=\"${xdz:domain() }/js/plugins/layer/layer.min.js\"></script>\r\n");
		content.append("    <script src=\"${xdz:domain() }/js/kkpager.min.js\"></script>\r\n");
		content.append("    <script src=\"${xdz:domain() }/js/pagination.js\"></script>\r\n");
		content.append("    <script type=\"text/javascript\">\r\n");
		content.append("    	function openAdd() {\r\n");
		content.append("    		location.href = \"../"+attiName+"/addPage\";\r\n");
		content.append("    	}\r\n");
		content.append("\r\n");
		content.append("    	function del(id) {\r\n");
		content.append("    		layer.confirm('是否确认删除？', {\r\n");
		content.append("    				btn: ['确认','取消']\r\n");
		content.append("    			}, function(){\r\n");
		content.append("    				location.href = \"../"+attiName+"/delete?id=\"+id;\r\n");
		content.append("    			}, function(){\r\n");
		content.append("    				layer.close();\r\n");									
		content.append("    			});\r\n");
		content.append("    		}\r\n");
		content.append("\r\n");
		content.append("    	function detail(id) {\r\n");
		content.append("    				location.href = \"../"+attiName+"/detail?id=\"+id;\r\n");
		content.append("    		}\r\n");
		content.append("\r\n");
		content.append("		kkpager.generPageHtml({\r\n");
		content.append("			pno : '${extQuery.pageNum }',\r\n");
		content.append("			mode : 'click', //设置为click模式\r\n");
		content.append("			//总页码\r\n");
		content.append("			total : '${extQuery.totalPage}',\r\n");
		content.append("			//总数据条数 \r\n");
		content.append("			totalRecords : '${extQuery.total}',\r\n");
		content.append("			//点击页码、页码输入框跳转、以及首页、下一页等按钮都会调用click\r\n");
		content.append("			//适用于不刷新页面，比如ajax\r\n");
		content.append("			click : function(n){\r\n");
		content.append("				//这里可以做自已的处理\r\n");
		content.append("				//...\r\n");
		content.append("				this.selectPage(n);\r\n");
		content.append("				toPage(n, '${extQuery.totalPage}', '"+attiName+"');\r\n");
		content.append("				this.selectPage(n);\r\n");
		content.append("				//处理完后可以手动条用selectPage进行页码选中切换\r\n");
		content.append("\r\n");
		content.append("			},\r\n");
		content.append("			//getHref是在click模式下链接算法，一般不需要配置，默认代码如下\r\n");
		content.append("			getHref : function(n){\r\n");
		content.append("				return '#';\r\n");
		content.append("			}\r\n");
		content.append("\r\n");
		content.append("		});\r\n");
		content.append("    </script>\r\n");
		content.append("</body>\r\n");
		content.append("</html>\r\n");
		
		String filePath =savePath+ attiName + "List.jsp";
		writerFile(filePath, content.toString());
	}
	
	
	/**
	 * 生成JSPUpdateFile
	 * 
	 * @param columns
	 * @throws IOException
	 */
	private void generateJSPUpdateFile(String packageStr, String tableName,String titleName, Map<String, TableBean> columns, String savePath) throws IOException {

		StringBuffer content = new StringBuffer();
		
		String beanName=CharacterUtil.returnBeanName(tableName);
		String attiName=CharacterUtil.firstLowCase(beanName);
		
		content.append("<%@ page language=\"java\" contentType=\"text/html; charset=UTF-8\" pageEncoding=\"UTF-8\"%>\r\n");
		content.append("<%@ taglib prefix=\"c\" uri=\"http://java.sun.com/jsp/jstl/core\"%>\r\n");
		content.append("<%@ taglib uri=\"http://java.sun.com/jsp/jstl/fmt\" prefix=\"fmt\" %>\r\n");
		content.append("<%@ taglib prefix=\"xdz\" uri=\"/xdztools\" %>\r\n");
		content.append("<!DOCTYPE html>\r\n");
		content.append("<html lang=\"zh-CN\">\r\n");
		content.append("<head>\r\n");
		content.append("<meta charset=\"utf-8\">\r\n");
		content.append("<link rel=\"stylesheet\" href=\"${xdz:domain() }/css/bootstrap.min.css\">\r\n");
		content.append("<link rel=\"stylesheet\" type=\"text/css\" href=\"${xdz:domain() }/css/plugins/morris/morris-0.4.3.min.css\">\r\n");
		content.append("<link rel=\"stylesheet\" type=\"text/css\" href=\"${xdz:domain() }/css/font-awesome.min.css\">\r\n");
//		content.append("<link rel=\"stylesheet\" href=\"${xdz:domain() }/css/style.min.css\">\r\n");
		content.append("<link rel=\"stylesheet\" href=\"${xdz:domain() }/css/parsley.css\" >\r\n");
		content.append("<script type=\"text/javascript\" src=\"${xdz:domain() }/js/plugins/My97DatePicker/WdatePicker.js\"></script> \r\n");
		content.append("<title>"+titleName+"修改</title>\r\n");
		content.append("</head>\r\n");
		content.append("<body>\r\n");
		content.append("    <form action=\"../" + attiName + "/update\" class=\"form-horizontal\" id=\"" + attiName + "Form\" method=\"post\" data-parsley-validate role=\"form\">\r\n");
		content.append("        <div class=\"panel panel-default\">\r\n");
		content.append("        	<header class=\"panel-heading\"><h3 class=\"panel-title\">"+titleName+"修改管理</h3></header>\r\n");
//		content.append("    	 	<div class=\"panel-heading\">\r\n");
//		content.append("           	 	<div class=\"panel-title\">"+titleName+"修改管理</div>\r\n");
//		content.append("   		 	</div>\r\n");
		content.append("            <div class=\"panel-body\">\r\n");
		content.append("                    <input type=\"hidden\"  name=\"id\" id=\"id\"  value=\"${" + attiName + ".id }\">\r\n");
		for (Entry<String, TableBean> entry : columns.entrySet()) {
			String columnName = CharacterUtil.firstLowCase(entry.getKey());
			if (!columnName.equals("id")) {
				content.append("            <div class=\"form-group\">\r\n");
				content.append("                 <label class=\"col-md-2 control-label\">" + entry.getValue().getRemarks() + "</label>\r\n");
				content.append("                 <div class=\"col-md-8\">\r\n");
				//获取类型判断是不是时间类型
				String type = columns.get(entry.getKey()).getColumnType();
				ColumnTypeEnum columnType = ColumnTypeEnum.instanceOf(type);
				String objType = columnType.getObjType();
				
				if("Date".equals(objType)){
					content.append("                     <input type=\"text\" onclick=\"WdatePicker({dateFmt:'yyyy-MM-dd HH:mm:ss'})\" name=\"str" +  CharacterUtil.firstUpperCase(columnName) + "\" placeholder=\"\" id=\"str" +  CharacterUtil.firstUpperCase(columnName) + "\" class=\"input-sm form-control Wdate\" required=\"required\" value=\"${" + attiName + ".str" +  CharacterUtil.firstUpperCase(columnName) + " }\">\r\n");			
				}else if("Integer".equals(objType)&&"status".equals(columnName)){
					content.append("                     <select name=\"status\" id=\"status\" class=\"form-control input-sm\">\r\n");		
					content.append("                            <option value=\"1\" <c:if test=\"${" + attiName + "." + columnName + " == 1}\">selected</c:if> >启用</option>\r\n");		
					content.append("                            <option value=\"0\" <c:if test=\"${" + attiName + "." + columnName + " == 0}\">selected</c:if> >禁用</option>\r\n");		
					content.append("                     </select>\r\n");		
				}else{
					content.append("                     <input type=\"text\" name=\"" + columnName + "\" placeholder=\"\" id=\"" + columnName + "\" class=\"input-sm form-control\" required=\"required\" value=\"${" + attiName + "." + columnName + " }\">\r\n");			
				}
				content.append("                 </div>\r\n");
				content.append("           </div>\r\n");
			}
		}
		
		content.append("                    <div class=\"form-group\">\r\n");
		content.append("                    	<label class=\"col-md-2 control-label\"></label>\r\n");
		content.append("                        <div class=\"col-md-8\">\r\n");
		content.append("                            <button type=\"submit\" class=\"btn btn-primary\">保存</button>\r\n");			
		content.append("                            <button type=\"button\" class=\"btn btn-white\" onclick=\"back()\">取消</button>\r\n");
		content.append("                        </div>\r\n");
		content.append("                    </div>\r\n");
		content.append("            </div>\r\n");
		content.append("        </div>\r\n");
		content.append("    </form>\r\n");
		content.append("    	<script src=\"${xdz:domain() }/js/jquery.min.js\"></script>\r\n");
		content.append("    	<script src=\"${xdz:domain() }/js/bootstrap.min.js\"></script>\r\n");
		content.append("    	<script src=\"${xdz:domain() }/js/plugins/parsley/parsley.min.js\"></script>\r\n");
		content.append("    	<script src=\"${xdz:domain() }/js/plugins/parsley/zh_cn.js\"></script>\r\n");
		content.append("    	<script type=\"text/javascript\">\r\n");
		content.append("    		function back(){\r\n");
		content.append("    			history.go(-1);\r\n");
		content.append("    		}\r\n");
		content.append("    </script>\r\n");
		content.append("</body>\r\n");
		content.append("</html>\r\n");
		
		String filePath = savePath+ attiName + "Update.jsp";
		writerFile(filePath, content.toString());
	}
	
	
	
	private void generateJSPDetailFile(String packageStr, String tableName,String titleName, Map<String, TableBean> columns, String savePath) throws IOException {

		StringBuffer content = new StringBuffer();
		
		String beanName=CharacterUtil.returnBeanName(tableName);
		String attiName=CharacterUtil.firstLowCase(beanName);
		
		content.append("<%@ page language=\"java\" contentType=\"text/html; charset=UTF-8\" pageEncoding=\"UTF-8\"%>\r\n");
		content.append("<%@ taglib prefix=\"c\" uri=\"http://java.sun.com/jsp/jstl/core\"%>\r\n");
		content.append("<%@ taglib uri=\"http://java.sun.com/jsp/jstl/fmt\" prefix=\"fmt\" %>\r\n");
		content.append("<%@ taglib prefix=\"xdz\" uri=\"/xdztools\" %>\r\n");
		content.append("<!DOCTYPE html>\r\n");
		content.append("<html lang=\"zh-CN\">\r\n");
		content.append("<head>\r\n");
		content.append("<meta charset=\"utf-8\">\r\n");
		content.append("<link rel=\"stylesheet\" href=\"${xdz:domain() }/css/bootstrap.min.css\">\r\n");
		content.append("<link rel=\"stylesheet\" type=\"text/css\" href=\"${xdz:domain() }/css/plugins/morris/morris-0.4.3.min.css\">\r\n");
		content.append("<link rel=\"stylesheet\" type=\"text/css\" href=\"${xdz:domain() }/css/font-awesome.min.css\">\r\n");
//		content.append("<link rel=\"stylesheet\" href=\"${xdz:domain() }/css/style.min.css\">\r\n");
		content.append("<link rel=\"stylesheet\" href=\"${xdz:domain() }/css/parsley.css\" >\r\n");
		content.append("<script type=\"text/javascript\" src=\"${xdz:domain() }/js/plugins/My97DatePicker/WdatePicker.js\"></script> \r\n");
		content.append("<title>"+titleName+"详情内容</title>\r\n");
		content.append("<!--[if lt IE 9]>\r\n");
		content.append("<script src=\"js/ie/respond.min.js\"></script>\r\n");
		content.append("<script src=\"js/ie/html5.js\"></script>\r\n");
		content.append("<![endif]-->\r\n");
		content.append("</head>\r\n");
		content.append("<body>\r\n");
		content.append("    <div class=\"container-fluid\">\r\n");
		content.append("       <div class=\"panel panel-default\">\r\n");
		content.append("          <header class=\"panel-heading\"><h3 class=\"panel-title\">"+titleName+"详情内容</h3></header>\r\n");
//		content.append("          <div class=\"panel-heading\">\r\n");
//		content.append("            <div class=\"panel-title\">"+titleName+"详情内容</div>\r\n");
//		content.append("          </div>\r\n");
		content.append("          <div class=\"panel-body\">\r\n");
		for (Entry<String, TableBean> entry : columns.entrySet()) {
			String columnName = CharacterUtil.firstLowCase(entry.getKey());
			if (!columnName.equals("id")) {
				content.append("                    <dl class=\"dl-horizontal\">\r\n");
				content.append("                        <dt><strong>" + entry.getValue().getRemarks() + "</strong></dt>\r\n");
				content.append("                        <dd>\r\n");
				
//				//获取类型判断是不是时间类型
				String type = columns.get(entry.getKey()).getColumnType();
				ColumnTypeEnum columnType = ColumnTypeEnum.instanceOf(type);
				String objType = columnType.getObjType();
				if("Date".equals(objType)){
					content.append("                           ${" + attiName + ".str" +  CharacterUtil.firstUpperCase(columnName) + " }\r\n");			
				}else if("Integer".equals(objType)&&"status".equals(columnName)){
					content.append("                           <c:if test=\"${" + attiName + "." + columnName + " == 1}\">启用</c:if>\r\n");		
					content.append("                           <c:if test=\"${" + attiName + "." + columnName + " == 0}\">禁用</c:if>\r\n");		
				}else{
					content.append("                            ${" + attiName + "." + columnName + " }\r\n");			
				}
				content.append("                        </dd>\r\n");
				content.append("                    </dl>\r\n");
			}
		}
		
		content.append("                    <div class=\"row\">\r\n");
		content.append("                    	<label class=\"col-md-2 control-label\"></label>\r\n");
		content.append("                        <div class=\"col-md-8\">\r\n");
		content.append("                            <button type=\"button\" class=\"btn btn-white\" onclick=\"back()\">返回</button>\r\n");
		content.append("                        </div>\r\n");
		content.append("                    </div>\r\n");
		content.append("               </div>\r\n");
		content.append("           </div>\r\n");
		content.append("        </div>\r\n");
		content.append("    	<script src=\"${xdz:domain() }/js/jquery.min.js\"></script>\r\n");
		content.append("    	<script src=\"${xdz:domain() }/js/bootstrap.min.js\"></script>\r\n");
		content.append("    	<script src=\"${xdz:domain() }/js/plugins/parsley/parsley.min.js\"></script>\r\n");
		content.append("    	<script src=\"${xdz:domain() }/js/plugins/parsley/zh_cn.js\"></script>\r\n");
		content.append("    	<script type=\"text/javascript\">\r\n");
		content.append("    		function back(){\r\n");
		content.append("    			history.go(-1);\r\n");
		content.append("    		}\r\n");
		
		
		content.append("    </script>\r\n");
		content.append("</body>\r\n");
		content.append("</html>\r\n");
		
		String filePath = savePath+ attiName + "Detail.jsp";
		writerFile(filePath, content.toString());
	}
	
	
	/**
	 * 生成JSPUpdateFile
	 * 
	 * @param columns
	 * @throws IOException
	 */
	private void generateJSPAddFile(String packageStr, String tableName,String titleName, Map<String, TableBean> columns, String savePath) throws IOException {

		StringBuffer content = new StringBuffer();
		
		String beanName=CharacterUtil.returnBeanName(tableName);
		String attiName=CharacterUtil.firstLowCase(beanName);
		
		content.append("<%@ page language=\"java\" contentType=\"text/html; charset=UTF-8\" pageEncoding=\"UTF-8\"%>\r\n");
		content.append("<%@ taglib prefix=\"c\" uri=\"http://java.sun.com/jsp/jstl/core\"%>\r\n");
		content.append("<%@ taglib uri=\"http://java.sun.com/jsp/jstl/fmt\" prefix=\"fmt\" %>\r\n");
		content.append("<%@ taglib prefix=\"xdz\" uri=\"/xdztools\" %>\r\n");
		content.append("<!DOCTYPE html>\r\n");
		content.append("<html lang=\"zh-CN\">\r\n");
		content.append("<head>\r\n");
		content.append("<meta charset=\"utf-8\">\r\n");
		content.append("<link rel=\"stylesheet\" href=\"${xdz:domain() }/css/bootstrap.min.css\">\r\n");
		content.append("<link rel=\"stylesheet\" type=\"text/css\" href=\"${xdz:domain() }/css/plugins/morris/morris-0.4.3.min.css\">\r\n");
		content.append("<link rel=\"stylesheet\" type=\"text/css\" href=\"${xdz:domain() }/css/font-awesome.min.css\">\r\n");
//		content.append("<link rel=\"stylesheet\" href=\"${xdz:domain() }/css/style.min.css\">\r\n");
		content.append("<link rel=\"stylesheet\" href=\"${xdz:domain() }/css/parsley.css\" >\r\n");
		content.append("<script type=\"text/javascript\" src=\"${xdz:domain() }/js/plugins/My97DatePicker/WdatePicker.js\"></script> \r\n");
		content.append("<title>"+titleName+"新增管理</title>\r\n");
		content.append("</head>\r\n");
		content.append("\r\n");
		content.append("\r\n");
		content.append("\r\n");
		content.append("<body>\r\n");
		content.append("    <form action=\"../" + attiName + "/insert\" class=\"form-horizontal\" id=\"" + attiName + "Form\" method=\"post\" data-parsley-validate role=\"form\">\r\n");
		content.append("        <div class=\"panel panel-default\">\r\n");
		content.append("          <header class=\"panel-heading\"><h3 class=\"panel-title\">"+titleName+"新增管理</h3></header>\r\n");
//		content.append("    		<div class=\"panel-heading\">\r\n");
//		content.append("            	<div class=\"panel-title\">"+titleName+"新增管理</div>\r\n");
//		content.append("    		</div>\r\n");
		content.append("            <div class=\"panel-body\">\r\n");
		for (Entry<String, TableBean> entry : columns.entrySet()) {
			String columnName = CharacterUtil.firstLowCase(entry.getKey());
			if (!columnName.equals("id")) {
				content.append("                    <div class=\"form-group\">\r\n");
				content.append("                        <label class=\"col-md-2 control-label\">" + entry.getValue().getRemarks() + "</label>\r\n");
				content.append("                        <div class=\"col-md-8\">\r\n");
				//获取类型判断是不是时间类型
				String type = columns.get(entry.getKey()).getColumnType();
				ColumnTypeEnum columnType = ColumnTypeEnum.instanceOf(type);
				String objType = columnType.getObjType();
				if("Date".equals(objType)){
					content.append("                            <input type=\"text\"  onclick=\"WdatePicker({dateFmt:'yyyy-MM-dd HH:mm:ss'})\" name=\"str" +  CharacterUtil.firstUpperCase(columnName) + "\" placeholder=\"\" id=\"str" +  CharacterUtil.firstUpperCase(columnName) + "\" class=\"input-sm form-control Wdate\" required=\"required\">\r\n");			
				}else if("Integer".equals(objType)&&"status".equals(columnName)){
					content.append("                            <select name=\"status\" id=\"status\" class=\"form-control input-sm\">\r\n");		
					content.append("                            	<option value=\"1\" >启用</option>\r\n");		
					content.append("                            	<option value=\"0\" >禁用</option>\r\n");		
					content.append("                            </select>\r\n");		
				}else{
					content.append("                            <input type=\"text\" name=\"" + columnName + "\" placeholder=\"\" id=\"" + columnName + "\" class=\"input-sm form-control\" required=\"required\">\r\n");			
				}
				content.append("                        </div>\r\n");
				content.append("                    </div>\r\n");
			}
		}
		
		content.append("                    <div class=\"form-group\">\r\n");
		content.append("                    	<label class=\"col-md-2 control-label\"></label>\r\n");
		content.append("                        <div class=\"col-md-8\">\r\n");
		content.append("                            <button type=\"submit\" class=\"btn btn-primary\">保存</button>\r\n");			
		content.append("                            <button type=\"button\" class=\"btn btn-white\" onclick=\"back()\">取消</button>\r\n");
		content.append("                        </div>\r\n");
		content.append("                    </div>\r\n");
		content.append("            </div>\r\n");
		content.append("        </div>\r\n");
		content.append("    </form>\r\n");
		content.append("   <script src=\"${xdz:domain() }/js/jquery.min.js\"></script>\r\n");
		content.append("   <script src=\"${xdz:domain() }/js/bootstrap.min.js\"></script>\r\n");
		content.append("   <script src=\"${xdz:domain() }/js/plugins/parsley/parsley.min.js\"></script>\r\n");
		content.append("   <script src=\"${xdz:domain() }/js/plugins/parsley/zh_cn.js\"></script>\r\n");
		content.append("   <script type=\"text/javascript\">\r\n");
		content.append("   		 function back(){\r\n");
		content.append("       		 history.go(-1);\r\n");
		content.append("    	}\r\n");
		content.append("    </script>\r\n");
		content.append("</body>\r\n");
		content.append("</html>\r\n");
		
		String filePath = savePath+ attiName + "Add.jsp";
		writerFile(filePath, content.toString());
	}
}
